// AWTComponent.h: interface for the AWTComponent class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_AWTCOMPONENT_H__1434121A_3D94_11D2_A3EF_006097A44215__INCLUDED_)
#define AFX_AWTCOMPONENT_H__1434121A_3D94_11D2_A3EF_006097A44215__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

//#include "AWTColor.h"
#include "AWTComponentListener.h"
#include "AWTFocusListener.h"
#include "AWTKeyListener.h"
#include "AWTMouseListener.h"
#include "AWTMouseMotionListener.h"
#include "AWTWindowListener.h"
#include "AWTEventMulticaster.h"

class AFX_EXT_CLASS AWTComponent : public AWTObject
{
DECLARE_DYNAMIC(AWTComponent)
public:
	AWTComponent();
	virtual ~AWTComponent();

public:

	virtual CString getName()
		{return m_name;}
	virtual void setName(CString& name)
		{
		m_name = name;
		}
	virtual AWTComponent* getParent()
		{return m_parent;}
	virtual void setParent(AWTComponent* parent)
		{m_parent = parent;}
	virtual BOOL isValid()
		{return m_valid;}
	virtual BOOL isVisible()
		{return m_visible;}
	virtual BOOL isShowing();
	virtual BOOL isEnabled()
		{return m_enabled;}
	virtual void setEnabled(BOOL b);
	virtual void setVisible(BOOL b);
	virtual AWTColor*	getForeground();
//		{return m_foregnd;}
	virtual void	setForeground(AWTColor* c)
		{if (m_foregnd != NULL) delete m_foregnd; m_foregnd = c;}
	virtual AWTColor*	getBackground();
	virtual void	setBackground(AWTColor* c);
	virtual HFONT getFont()
		{return m_font;}
	virtual void setFont(HFONT f);
	virtual CPoint getLocation()
		{return CPoint(m_x, m_y);}
	virtual CPoint getLocationOnScreen()
		{return CPoint(0, 0);}
	virtual void setLocation(int x, int y)
		{move(x,y);}
	virtual void setLocation(CPoint pt)
		{move(pt.x,pt.y);}
	virtual void move(int x,int y)
		{setBounds(x,y,m_w,m_h);}
	virtual CSize getSize()
		{return CSize(m_w,m_h);}
	virtual void setSize(int w, int h)
		{resize(w, h);}
	virtual void resize(int w, int h)
		{setBounds(m_x, m_y, w, h);}
	virtual void setSize(CSize sz)
		{resize(sz.cx, sz.cy);}
	virtual void resize(CSize sz)
		{setSize(sz.cx, sz.cy);}
	virtual CRect getBounds()
		{return CRect(m_x, m_y, m_x+m_w, m_y+m_h);}
	virtual void setBounds(int x, int y, int w, int h)
		{reshape(x,y,w,h);}
	virtual void reshape(int x, int y, int w, int h);
	virtual void setBounds(CRect rc)
		{setBounds(rc.left, rc.top, rc.Width(), rc.Height());}
	virtual CSize getPreferredSize()
		{return preferredSize();}
	virtual CSize preferredSize()
		{return m_prefSize;}
	virtual CSize getMinimumSize()
		{return minimumSize();}
	virtual CSize minimumSize()
		{return m_minSize;}
	virtual void doLayout()
		{layout();}	
	virtual void layout(){}	
	virtual void validate()
		{if (!m_valid) m_valid = TRUE;}
//	virtual void invalidate();
	void invalidate();
	virtual CWnd* createComponent()	= 0;
	virtual void addNotify();
	virtual void removeNotify();
	virtual CWnd* getPeer()
		{return m_peer;}
	void setPeer(CWnd* w)
		{m_peer = w;}
	int getWidth()
		{return m_w;}
	int getHeight()
		{return m_h;}
	virtual CBrush* getBkBrush();
	void transferFocus()
		{nextFocus();}
	virtual void transferFocus(AWTComponent* base){};
	void nextFocus()
		{if (m_parent != NULL) m_parent->transferFocus(this);}
	virtual void nextFocus(AWTComponent* base){};
	
	void addComponentListener(AWTComponentListener* l)
		{m_componentListener = AWTEventMulticaster::add(m_componentListener, l);}
  void removeComponentListener(AWTComponentListener* l) 
		{m_componentListener = AWTEventMulticaster::remove(m_componentListener, l);}        
	void processComponentEvent(AWTComponentEvent* e);

	void addFocusListener(AWTFocusListener* l)
		{m_focusListener = AWTEventMulticaster::add(m_focusListener, l);}
  void removeFocusListener(AWTFocusListener* l) 
		{m_focusListener = AWTEventMulticaster::remove(m_focusListener, l);}        
	void processFocusEvent(AWTFocusEvent* e);

	void addKeyListener(AWTKeyListener* l)
		{m_keyListener = AWTEventMulticaster::add(m_keyListener, l);}
  void removeKeyListener(AWTKeyListener* l) 
		{m_keyListener = AWTEventMulticaster::remove(m_keyListener, l);}        
	void processKeyEvent(AWTKeyEvent* e);

	void addMouseListener(AWTMouseListener* l)
		{m_mouseListener = AWTEventMulticaster::add(m_mouseListener, l);}
  void removeMouseListener(AWTMouseListener* l) 
		{m_mouseListener = AWTEventMulticaster::remove(m_mouseListener, l);}        
	void processMouseEvent(AWTMouseEvent* e);

	void addMouseMotionListener(AWTMouseMotionListener* l)
		{m_mouseMotionListener = AWTEventMulticaster::add(m_mouseMotionListener, l);}
  void removeMouseMotionListener(AWTMouseMotionListener* l) 
		{m_mouseMotionListener = AWTEventMulticaster::remove(m_mouseMotionListener, l);}        

//	virtual void requestFocus()
//		{if (m_peer != NULL) m_peer->SetFocus(); m_focus = TRUE;}
	virtual void requestFocus();
	virtual BOOL isContainer()
		{return FALSE;}
	virtual BOOL isFocusTraversable()
		{return FALSE;}
	virtual void paint(CDC* pDC){};
	virtual void eraseBackground(CDC* pDC);
	void AWTComponent::repaint() 
		{if (m_peer != NULL) m_peer->Invalidate();}
	void repaint(int x, int y, int width, int height) 
		{if (m_peer != NULL) m_peer->InvalidateRect(CRect(x, y, x + width, y + height));}
	CDC* getGraphics()
		{return (m_peer == NULL ? NULL : m_peer->GetDC());}
	void freeGraphics(CDC* pdc)
		{if (m_peer != NULL) m_peer->ReleaseDC(pdc);}
	BOOL hasFocus()
		{return m_focus;}
	void setCursor(HCURSOR c)
		{m_cursor = c;}
	HCURSOR getCursor()
		{return m_cursor;}

protected:
	CWnd* m_peer;
	CBrush* m_brush;
	AWTComponent* m_parent;
	int m_x;
	int m_y;
	int m_w;
	int m_h;
	AWTColor* m_foregnd;
	AWTColor* m_backgnd;
	HFONT m_font;
	BOOL m_visible;
	BOOL m_enabled;
	BOOL m_valid;
	CString m_name;
  CSize m_minSize;
  CSize m_prefSize;
	HCURSOR m_cursor;

  AWTComponentListener* m_componentListener;
  AWTFocusListener* m_focusListener;
  AWTKeyListener* m_keyListener;
  AWTMouseListener* m_mouseListener;
  AWTMouseMotionListener* m_mouseMotionListener;

private:
	BOOL m_focus;
};

#endif // !defined(AFX_AWTCOMPONENT_H__1434121A_3D94_11D2_A3EF_006097A44215__INCLUDED_)

